package org.happycomp.radiog.utils;

import org.eclipse.ui.IWorkbenchPartSite;
import org.happycomp.radio.downloader.DownloadingItem;
import org.happycomp.radio.scheduler.SchedulerListener;

public class SchedulerAdapter implements SchedulerListener {

	private SchedulerListener[] listeners;
	private IWorkbenchPartSite site;
	
	public SchedulerAdapter(IWorkbenchPartSite site,  SchedulerListener[] listeners) {
		super();
		this.listeners = listeners;
		this.site = site;
	}

	@Override
	public void exceptionOccured(final Throwable arg0) {
		site.getShell().getDisplay().asyncExec(new Runnable() {
			
			@Override
			public void run() {
				for (SchedulerListener listener : listeners) {
					listener.exceptionOccured(arg0);
				}
			}
		});
	}

	@Override
	public void refreshInterval() {
		site.getShell().getDisplay().asyncExec(new Runnable() {
			
			@Override
			public void run() {
				for (SchedulerListener listener : listeners) {
					listener.refreshInterval();
				}
			}
		});
	}

	@Override
	public void startDownloading() {
		site.getShell().getDisplay().asyncExec(new Runnable() {
			
			@Override
			public void run() {
				for (SchedulerListener listener : listeners) {
					listener.startDownloading();
				}
			}
		});
	}

	@Override
	public void stopDownloading(final DownloadingItem arg0) {
		site.getShell().getDisplay().asyncExec(new Runnable() {
			
			@Override
			public void run() {
				for (SchedulerListener listener : listeners) {
					listener.stopDownloading(arg0);
				}
			}
		});
	}

	@Override
	public void shutDown() {
		site.getShell().getDisplay().asyncExec(new Runnable() {
			
			@Override
			public void run() {
				for (SchedulerListener listener : listeners) {
					listener.shutDown();
				}
			}
		});
	}
	
	
}
